import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;

public class NGuessNumberTest {
}
     class generateAnswerTest{
        @Test
        void generateAnswerTest(){
            //检查答案数字数量是不是4,其中是不是无重复数字,以及数字是不是都在0-9之间
            int s = 4;

            NGuessNumber nGuessNumber = new NGuessNumber();

            assertEquals(s,nGuessNumber.generateAnswer().length);
            System.out.println("生成数字数量是4,正确");

            int num [] = nGuessNumber.generateAnswer();

            boolean flag = false;
            int numsize = 0;

            for (int i = 0; i < s; i++) {
                if (num[i] >= 0&&num[i]<=9){
                    numsize = 1;
                }else {
                    numsize = 0;
                }
                for (int l = 0;l<=i;l++){
                    if (i!=l){
                        if (num[i] == num[l]){
                            flag = false;
                        }else {
                            flag = true;
                        }
                    }
                }
            }
            assertEquals(true,flag);
            System.out.println("其中无重复数字,正确");
            assertEquals(1,numsize);
            System.out.println("数字都在0-9之间,正确");

        }
        //getPlayerInputTest方法
        static class getPlayerInputTest{
            @Test
            void getPlayerInput(){
                //断言检查玩家猜测的数字数量是否是4个
                int numsize = 4;
                NGuessNumber nGuessNumber = new NGuessNumber();
                assertEquals(numsize,nGuessNumber.guesslist.length);
                System.out.println("玩家输入的数字数量是4个,正确");
                System.out.println("哈哈哈哈哈哈,,,,累死老子了");
            }
        }
        //compareGuessAnswerTest方法
        static class compareGuessAnswerTest{
            @Test
            void compareGuessAnswer(){
                NGuessNumber nGuessNumber = new NGuessNumber();

                int testguess []= nGuessNumber.guesslist;
                int testnum [] = nGuessNumber.generateAnswer();
                int A_num = 0;
                int B_num = 0;
                for (int i = 0; i < testnum.length; i++) {
                    for (int j = 0; j < testnum.length; j++) {
                        if (i!=j){
                            if (testnum[i]==testguess[j]){
                                B_num++;
                            }
                        }else {
                            if (testnum[i] == testguess[j]){
                                A_num++;
                            }
                        }
                    }
                }
                String s = A_num+"A"+B_num+"B\n"+"A表示存在且位置正确的数字个数,B表示存在且位置不正确的数字个数! \n"+"如: 1A2B,表示你猜测的四个数字有3个是对的,有一个位置对,两个位置不对.\n";

                assertEquals(s,nGuessNumber.compareGuessAnswer());

                System.out.println();
                System.out.println("测试比较玩家猜测和答案后,返回的提示信息,正确");
            }
        }

        //isWin方法
         static class isWin{
            @Test
            void isWIn(){
                NGuessNumber nGuessNumber = new NGuessNumber();
                if (nGuessNumber.isWin() == true){
                    assertEquals(true,nGuessNumber.isWin());
                    System.out.println("根据提示信息中A的数量判断玩家是否获胜,如果获胜返回true,否则返回false,返回结果类型正确");
                }else if (nGuessNumber.isWin() == false){
                    assertEquals(false,nGuessNumber.isWin());
                    System.out.println("根据提示信息中A的数量判断玩家是否获胜,如果获胜返回true,否则返回false,返回结果类型正确");
                }else {
                    assertEquals(true, nGuessNumber.isWin());
                    assertEquals(false, nGuessNumber.isWin());
                    System.out.println("根据提示信息中A的数量判断玩家是否获胜,如果获胜返回true,否则返回false,返回结果类型错误");
                }
            }
        }
    }















